<template>
    <div class="minequestionnaire">
        <div class="title">个人问卷</div>
        <div class="mineQuestionBox">
            <transition-group name="questionnaire">
                <div v-for="(item, index) in this.$store.state.question" :key="item">
                    <questionnaire v-if="!this.$store.state.question[index].inRecycleBin" :index="index"
                        @pushIndex="getIndex"></questionnaire>
                </div>
            </transition-group>
        </div>

        <div class="background" v-if="sureDelete">
            <div class="sureDelete">
                <h2>移动到回收站</h2>
                <img src="../../assets/close.png" alt="" @click="cancel">
                <p>确定要将问卷《{{this.$store.state.question[questionIndex].totalTitle}}》移动到回收站吗？</p>
                <hr>
                <div class="sure" @click="sure">确定</div>
                <div class="cancel" @click="cancel">取消</div>
            </div>
        </div>

        <div class="background" v-if="sureIssue">
            <div class="sureDelete">
                <h2>投放问卷</h2>
                <img src="../../assets/close.png" alt="" @click="cancelStatistics">
                <p>确定要投放问卷《{{this.$store.state.question[questionIndex].totalTitle}}》吗？投放问卷后不可再对问卷进行编辑。</p>
                <hr>
                <div class="sure" @click="sureStatistics">确定</div>
                <div class="cancel" @click="cancelStatistics">取消</div>
            </div>
        </div>
    </div>
</template>

<script>
    import questionnaire from '../questionnaire/questionnaire.vue'
    import {
        is_recycle
    } from '@/util/apis'
    export default {
        components: {
            questionnaire
        },
        data() {
            return {
                questionIndex: 0,
                sureDelete: false,
                sureIssue: false,
            }
        },
        methods: {
            sureStatistics(){
                this.$store.commit('sureIssue', this.questionIndex)
            },
            getIndex(questionId, sureDelete) {
                this.questionIndex = questionId
                this.sureDelete = sureDelete
            },
            cancel() {
                this.sureDelete = false
            },
            cancelStatistics(){
                this.sureStatistics = false
            },
            sure() {
                this.$store.commit('intoRecycleBin', this.questionIndex)
                // 放入回收站
                let params = {
                    username:sessionStorage.getItem('username'),
                    id : this.$store.state.question[this.questionIndex].id,
                    inRecycleBin:true
                }
                is_recycle(params).then((response) => {
                    console.log(response)
                }).catch((error) => {
                    console.log(error)
                })
                this.sureDelete = false
            }
        },
        computed: {

        }
    }
</script>

<style scoped>
    .minequestionnaire {
        background-color: gray;
        padding: 10px;
        flex: 1;
        overflow: auto;
    }

    .mineQuestionBox {
        display: flex;
        flex-wrap: wrap;
    }

    .title {
        width: 100%;
        height: 20px;
        color: #fff;
        line-height: 20px;
        margin: 20px 0;
    }

    .questionnaire-enter-active,
    .questionnaire-leave-active {
        transition: all .8s;
    }

    .questionnaire-enter-from,
    .questionnaire-leave-to {
        opacity: 0;
        transform: translateY(70px);
    }

    .questionnaire-move {
        transform: all .8s;
    }

    .background {
        position: fixed;
        width: 100vw;
        height: 100vh;
        top: 0;
        left: 0;
        background-color: rgba(0, 0, 0, .6);
        z-index: 99;
    }

    .sureDelete {
        position: relative;
        width: 400px;
        height: 300px;
        top: 50%;
        transform: translateY(-50%);
        margin: 0 auto;
        background-color: #fff;
        border-radius: 1rem;
    }

    .sureDelete>h2 {
        position: absolute;
        top: 20px;
        left: 30px;
    }

    .sureDelete>p {
        position: absolute;
        top: 80px;
        left: 30px;
    }

    .sureDelete>img {
        position: absolute;
        width: 30px;
        height: 30px;
        top: 15px;
        right: 20px;
        cursor: pointer;
    }

    .sureDelete>hr {
        position: absolute;
        width: 100%;
        left: 0;
        bottom: 80px;
    }

    .sure {
        position: absolute;
        width: 90px;
        height: 40px;
        bottom: 20px;
        right: 30px;
        background-color: #4187f6;
        color: #fff;
        font-size: 1.1rem;
        line-height: 40px;
        text-align: center;
        cursor: pointer;
        border-radius: 10px;
    }

    .cancel {
        position: absolute;
        width: 90px;
        height: 40px;
        bottom: 20px;
        right: 130px;
        background-color: #fff;
        border: 1px solid #e1e7f2;
        font-size: 1.1rem;
        line-height: 40px;
        text-align: center;
        cursor: pointer;
        border-radius: 10px;
    }
</style>